cards = [{'name': 'mia', 'phone': '14570456976', 'qq': '4574878476', 'email': '4574878476@qq.com'},
         {'name': 'tom', 'phone': '109436836', 'qq': '3473634634', 'email': '42345345634@qq.com'},
         {'name': 'jack', 'phone': '20968236', 'qq': '7342.634537563', 'email': '6583536536@qq.com'}]  # 所有用户


def menu():
    print('*' * 30)
    print('''欢迎使用【名片管理系统】
    1.新建名片
    2.显示全部
    3.查询名片
    0.退出系统''')
    print('*' * 30)


def new_card(name, phone, qq, email):
    # 单个用户添加
    user = {
        'name': name,
        'phone': phone,
        'qq': qq,
        'email': email
    }
    cards.append(user)
    return True


def show_card():
    fg = 0
    for card in cards:
        fg += 1
        print('-' * 5 + '%d' % fg + '-' * 5)
        for k, v in card.items():
            print(k, v)


def query_card(kw):
    for card in cards:
        for k, v in card.items():
            if kw == v:
                return card
    return False


def modify_card(card):
    pass


def del_card(card):
    cards.remove(card)


def quit():
    print('欢迎下次使用【名片管理系统】')


def main():
    menu()
    while True:
        op = input('请输入你要操作的序号：')
        if op == '1':
            name = input('请输入你的姓名：')
            phone = input('请输入你的电话号码：')
            qq = input('请输入你的QQ号码：')
            email = input('请输入你的邮箱账号：')
            result = new_card(name, phone, qq, email)
            if result:
                print('成功新建一个名片')
            else:
                print('请重试')
        elif op == '2':
            show_card()
        elif op == '3':
            kw = input('请输入查询关键字：')
            result = query_card(kw)
            if result:
                for k, v in result.items():
                    print(k, v)
                op2 = input('输入4修改名片，输入5删除名片：')
                if op2 == 4:
                    modify_card(result)
                elif op2 == 5:
                    del_card(result)
            else:
                print('没有查到相关信息2')
        elif op == '0':
            quit()
            break
        else:
            print('请重试')
